//点击like按钮
function like(element) {
    var invitationId = element.previousElementSibling.value;
    //这边用于修改状态
    fetch('/update/invitation/likeStatus?invitationId=' + invitationId)
        .then(function (res) {
            return res.text();
        })
        .then(function (data) {
            if (data == 1) {
                element.style.color = "#fa4d6c";
                element.lastElementChild.innerHTML++;
            } else if (data == 0) {
                element.style.color = "#afafaf";
                element.lastElementChild.innerHTML--;
            } else if (data == -2) {
                alert("请先登录");
            } else {
                alert("未知错误");
            }
            //这边用于刷新
            fetch('/update/invitation/like?invitationId=' + invitationId)
                .then(function (res) {
                    return res.text();
                })
                .then(function (data) {
                    if (data >= 0) {
                        element.lastElementChild.innerHTML = data;
                    } else {
                        alert(data);
                    }
                }).catch(function (e) {
                    alert("error:" + e);
                })
        }).catch(function (e) {
            alert("error:" + e);
        })
}
//点击star(帖子)按钮
function star(element) {
    var invitationId = element.previousElementSibling.previousElementSibling.value;
    //这边用于修改状态
    fetch("/update/target/starStatus?targetType=invitation&targetId=" + invitationId)
        .then(function (res) {
            return res.text();
        })
        .then(function (data) {
            if (data == 1) {
                element.style.color = "#ffc761";
                element.lastElementChild.innerHTML++;
            } else if (data == 0) {
                element.style.color = "#afafaf";
                element.lastElementChild.innerHTML--;
            } else if (data == -2) {
                alert("请先登录");
            } else {
                alert("未知错误");
            }
            //这边用于刷新
            fetch("/update/target/star?targetType=invitation&targetId=" + invitationId)
                .then(function (res) {
                    return res.text();
                })
                .then(function (data) {
                    if (data >= 0) {
                        element.lastElementChild.innerHTML = data;
                    } else {
                        alert(data);
                    }
                }).catch(function (e) {
                    alert("error:" + e);
                })
        }).catch(function (e) {
            alert("error:" + e);
        })
}
//用于关注用户
function starUser(element) {
    var userId = element.previousElementSibling.value;
    //这边用于修改状态
    fetch("/update/target/starStatus?targetType=user&targetId=" + userId)
        .then(function (res) {
            return res.text();
        })
        .then(function (data) {
            if (data == 1) {
                element.style.background = "#ff8d00";
                element.firstElementChild.setAttribute("class","fa fa-check");
                element.lastElementChild.innerHTML = "已关注";
            } else if (data == 0) {
                element.style.background = "#00d1b2";
                element.firstElementChild.setAttribute("class","fa fa-star");
                element.lastElementChild.innerHTML = "关注";
            } else if (data == -2) {
                alert("请先登录");
            } else {
                alert("未知错误");
            }
        }).catch(function (e) {
            alert("error:" + e);
        })
}